package com.zwy.rxjava2;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.zwy.rxjava.LogUtils;
import com.zwy.rxjava.R;

import rx.Observable;
import rx.Observer;

public class MainActivity222 extends Activity implements View.OnClickListener{


    private Button mBtn1;
    private Button mBtn2;
    private Button mBtn3;
    private Button mBtn4;
    private Button mBtn5;
    private Button mBtn6;
    private Button mBtn7;
    private Button mBtn8;
    private Button mBtn9;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

          LogUtils.allowD = true;
        LogUtils.customTagPrefix = "itchen";

        initView();
    }

    private void initView() {

        findViewById(R.id.button1).setOnClickListener(this);
        findViewById(R.id.button2).setOnClickListener(this);
        findViewById(R.id.button3).setOnClickListener(this);
        findViewById(R.id.button4).setOnClickListener(this);
        findViewById(R.id.button5).setOnClickListener(this);
        findViewById(R.id.button6).setOnClickListener(this);
        findViewById(R.id.button7).setOnClickListener(this);
        findViewById(R.id.button8).setOnClickListener(this);
        findViewById(R.id.button9).setOnClickListener(this);
        findViewById(R.id.button10).setOnClickListener(this);
        findViewById(R.id.button11).setOnClickListener(this);
        findViewById(R.id.button12).setOnClickListener(this);
//        mBtn1= (Button) findViewById(R.id.button);
//        mBtn1= (Button) findViewById(R.id.button);
//        mBtn1= (Button) findViewById(R.id.button);


        //Range操作符发射一个范围内的有序整数序列，你可以指定范围的起始和长度。
      //  RxJava将这个操作符实现为range函数，它接受两个参数，一个是范围的起始值，一个是范围的数据的数目。如果你将第二个参数设为0，将导致Observable不发射任何数据（如果设置为负数，会抛异常）。

        //做一个cast计算
        Observable.range(1,5).cast(Integer.class).subscribe(new Observer<Integer>() {
            @Override
            public void onCompleted() {
                LogUtils.d("------>onCompleted()");
            }

            @Override
            public void onError(Throwable e) {
                LogUtils.d("------>onError()" + e);
            }

            @Override
            public void onNext(Integer i) {
                LogUtils.d("------>onNext()" + i);
            }
        });

//        11-12 18:36:34.484 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onNext(L:77): ------>onNext()1
//        11-12 18:36:34.484 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onNext(L:77): ------>onNext()2
//        11-12 18:36:34.485 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onNext(L:77): ------>onNext()3
//        11-12 18:36:34.486 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onNext(L:77): ------>onNext()4
//        11-12 18:36:34.487 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onNext(L:77): ------>onNext()5
//        11-12 18:36:34.488 32658-32658/com.zwy.rxjava D/itchen:MainActivity222$1.onCompleted(L:67): ------>onCompleted()

}

    @Override
    public void onClick(View view) {
        Intent intent=null;
        switch (view.getId()){
            case R.id.button1:intent=new Intent(MainActivity222.this,NormalRxActivity.class);
                break;
            case R.id.button2: intent=new Intent(MainActivity222.this,RxMapActivity.class);
                break;
            case R.id.button3:intent=new Intent(MainActivity222.this,RxSchuderActivity.class);
                break;
            case R.id.button4:intent=new Intent(MainActivity222.this,RxFlatMapActivity.class);
                break;
            case R.id.button5:intent=new Intent(MainActivity222.this,RxMergeActivity.class);
                break;
            case R.id.button6:intent=new Intent(MainActivity222.this,RxBindingActivity.class);
                break;
            case R.id.button7:intent=new Intent(MainActivity222.this,RxFilterActivity.class);
                break;
            case R.id.button8:intent=new Intent(MainActivity222.this,RxTakeActivity.class);
                break;
            case R.id.button9:intent=new Intent(MainActivity222.this,RxTimerActivity.class);
                break;
            case R.id.button10:intent=new Intent(MainActivity222.this,RxSortActivity.class);
                break;
            case R.id.button11:intent=new Intent(MainActivity222.this,RxConnetActivity.class);
                break;
            case R.id.button12:intent=new Intent(MainActivity222.this,TimestampActivity.class);
                break;
        }
        startActivity(intent);
    }
}
